import VueRouter from 'vue-router';
import meun from './meun';
// 单独页面开始
const Login = () => import(/* webpackChunkName: "login" */ 'components/login/index');
const NotFound = () => import(/* webpackChunkName: "404" */ 'components/404/index');
const Console = () => import(/* webpackChunkName: "console" */ 'components/console');
// 单独页面结束
const configuration_home_index = () => import('components/configuration/home/index');
const configuration_home_section_analysis = () => import('components/configuration/home/sectionAnalysis');
const configuration_home_shop_analysis = () => import('components/configuration/home/shopAnalysis');
const configuration_home_group_analysis = () => import('components/configuration/home/groupAnalysis');
const configuration_home_personal_analysis = () => import('components/configuration/home/personalAnalysis');
const configuration_check_index = () => import('components/configuration/check/index');
const configuration_employee_index = () => import('components/configuration/employee/index');
const configuration_examination_index = () => import('components/configuration/examination/index');
const configuration_examination_creat = () => import('components/configuration/examination/examinationCreat');
const configuration_examination_add_employee = () => import('components/configuration/examination/addEmployee');
const configuration_examination_detail= () => import('components/configuration/examination/examinationDetail');
const configuration_examination_paper_result= () => import('components/configuration/examination/paperResult');
const configuration_management_index = () => import('components/configuration/management/index');
const configuration_question_bank_index = () => import('components/configuration/questionBank/index');
const configuration_question_bank_question_detail = () => import('components/configuration/questionBank/questionDetail');
const configuration_test_paper_index = () => import('components/configuration/testPaper/index');
const configuration_test_paper_paper_creat = () => import('components/configuration/testPaper/paperCreat');
const configuration_test_paper_paper_view = () => import('components/configuration/testPaper/paperView');
const configuration_system_login_log = () => import('components/configuration/system/loginLog');
const configuration_system_system_test = () => import('components/configuration/system/systemTest');
const configuration_exam_overdue_index = () => import('components/configuration/examOverdue/index');
const configuration_key_analysis_main_person = () => import('components/configuration/keyAnalysis/mainPerson');
const configuration_key_analysis_question = () => import('components/configuration/keyAnalysis/questionAnalysis');
const configuration_key_analysis_detail_person = () => import('components/configuration/keyAnalysis/detailPerson');
const router = new VueRouter({
  mode: 'hash',
  routes: [
    { path: '/', redirect: '/console' },
    {
      path: '/login',
      name: 'login',
      meta: { noLogin: true },
      component: Login,
      // 单独配置路由守卫，清除http请求内部的token
      beforeEnter: (to, from, next) => {
        localStorage.removeItem('TOKEN');
        return next();
      }
    },
    {
      path: '/console',
      component: Console,
      meta: { title: '' },
      name:'console',
      children: [
        { 
          path: 'configuration/keyAnalysis/questionAnalysis',
          name:"questionAnalysis",
          meta: { title: '错题统计' }, 
          component: configuration_key_analysis_question
        },
        { 
          path: 'configuration/keyAnalysis/mainPerson',
          name:"mainPerson",
          meta: { title: '重点人统计' }, 
          component: configuration_key_analysis_main_person
        },
        { 
          path: 'configuration/examOverdue/index',
          name:"examOverdue",
          meta: { title: '考试提醒' }, 
          component: configuration_exam_overdue_index
        },
        { 
          path: 'configuration/home/index',
          name:"homeIndex",
          meta: { title: '数据分析' }, 
          component: configuration_home_index
        },
        { 
          path: 'configuration/home/sectionAnalysis',
          name:"sectionAnalysis",
          meta: { title: '站段分析' }, 
          component: configuration_home_section_analysis
        },
        { 
          path: 'configuration/home/shopAnalysis',
          name:"shopAnalysis",
          meta: { title: '车间分析' }, 
          component: configuration_home_shop_analysis
        },
        { 
          path: 'configuration/home/groupAnalysis',
          name:"groupAnalysis",
          meta: { title: '小组分析' }, 
          component: configuration_home_group_analysis
        },
        { 
          path: 'configuration/home/personalAnalysis',
          name:"personalAnalysis",
          meta: { title: '个人分析' }, 
          component: configuration_home_personal_analysis
        },
        { 
          path: 'configuration/check/index',
          name:"checkIndex",
          meta: { title: '批改管理' }, 
          component: configuration_check_index
        },
        { 
          path: 'configuration/employee/index',
          name:"employeeIndex",
          meta: { title: '职工管理' }, 
          component: configuration_employee_index
        },
        { 
          path: 'configuration/examination/index',
          name:"examinationIndex",
          meta: { title: '考试管理' }, 
          component: configuration_examination_index
        },
        { 
          path: 'configuration/examination/examinationCreat',
          name:"examinationCreat",
          meta: { title: '考试管理' }, 
          component: configuration_examination_creat,
        },
        { 
          path: 'configuration/examination/examinationAddEmployee',
          name:"examinationAddEmployee",
          meta: { title: '考试管理' }, 
          component: configuration_examination_add_employee,
        },
        { 
          path: 'configuration/examination/examinationDetail',
          name:"examinationDetail",
          meta: { title: '考试管理' }, 
          component: configuration_examination_detail,
        },
        { 
          path: 'configuration/management/index',
          name:"managementIndex",
          meta: { title: '管理员管理' }, 
          component: configuration_management_index
        },
        { 
          path: 'configuration/questionBank/index',
          name:"questionBankIndex",
          meta: { title: '题库管理' }, 
          component: configuration_question_bank_index
        },
        { 
          path: 'configuration/questionBank/questionDetail',
          name:"questionDetail",
          meta: { title: '题目详情' }, 
          component: configuration_question_bank_question_detail
        },
        { 
          path: 'configuration/testPaper/index',
          name:"testPaperIndex",
          meta: { title: '试卷列表' }, 
          component: configuration_test_paper_index
        },
        { 
          path: 'configuration/testPaper/paperCreat',
          name:"testPaperCreate",
          meta: { title: '试卷创编' }, 
          component: configuration_test_paper_paper_creat
        },
        { 
          path: 'configuration/system/loginLog',
          name:"systemSet", 
          meta: { title: '登录日志' }, 
          component: configuration_system_login_log 
        },
        { 
          path: 'configuration/system/systemTest',
          name:"systemTest", 
          meta: { title: '设置测试'}, 
          component: configuration_system_system_test 
        }
      ]
    },
    { 
      path: '/paperView',
      name:"paperView",
      meta: { title: '试卷预览' }, 
      component: configuration_test_paper_paper_view
    },
    { 
      path: '/paperResult',
      name:"paperResult",
      meta: { title: '考试结果' }, 
      component: configuration_examination_paper_result
    },
    { 
      path: '/detailPerson',
      name:"detailPerson",
      meta: { title: '个人分析' }, 
      component: configuration_key_analysis_detail_person
    },
    { path: '*', component: NotFound }
  ]
});
router.beforeEach((to, from, next) => { //路由拦截,重定向
  // 1. 判断访问的是不是登录 页面
  if (to.path === '/login') {
    next()
  } else {
    if (localStorage.getItem('userInfo')) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router;
